package xfsale.service.impl.j2ee;

import xfsale.exception.AppException;
import xfsale.packet.BaseRequest;
import xfsale.packet.BaseResponse;

public abstract class BaseOrderAcct extends BaseOrder {

    public BaseOrderAcct(BaseRequest request, BaseResponse response) {
        super(request, response);
    }

    protected final void checkTAAccountID(String taAccountID) throws Exception {
        if (!taAccountID.matches("^[0-9a-zA-Z]{8,12}$")) {
            throw new AppException("基金帐号不合法");
        }
    }

    protected final void checkTACode(String taCode) throws Exception {
        if (!taCode.matches("^[0-9]{2,3}$")) {
            throw new AppException("TA代码不合法");
        }
    }

    protected final void checkCustType(String invstType) throws Exception {
        if (!invstType.matches("^[01]$")) {
            throw new AppException("投资者类型不合法");
        }
    }

    protected final void checkCustName(String invstName) throws Exception {
        if (!invstName.matches("^.{2,60}$")) {
            throw new AppException("投资者名称不合法");
        }
    }

    protected final void checkCustNameAbbr(String invstAbbr) throws Exception {
        if (!invstAbbr.matches("^.{2,12}$")) {
            throw new AppException("投资者简称不合法");
        }
    }

    protected final void checkNationality(String nationality) throws Exception {
        if (!nationality.matches("^[0-9]{3}$")) {
            throw new AppException("投资者国籍不合法");
        }
    }

    protected final void checkCertType(String certType) throws Exception {
        if (!certType.matches("^[0-9]$")) {
            throw new AppException("投资者证件类型不合法");
        }
    }

    protected final void checkCertNo(String certNo) throws Exception {
    }

    protected final void checkCertValidFrom(String certValidFrom) throws Exception {
        if (!certValidFrom.matches("^[0-9]{8}$")) {
            throw new AppException("投资者证件有效期起始日期不合法");
        }
    }

    protected final void checkCertValidTo(String certValidTo) throws Exception {
        if (!certValidTo.matches("^[0-9]{8}$")) {
            throw new AppException("投资者证件有效期结束日期不合法");
        }
    }

    protected final void checkAddress(String address) throws Exception {
        if (!address.matches("^.{5,60}$")) {
            throw new AppException("通讯地址不合法");
        }
    }

    protected final void checkPostCode(String postCode) throws Exception {
        if (!postCode.matches("^[0-9]{6}$")) {
            throw new AppException("邮政编码不合法");
        }
    }

    protected final void checkTelNo(String telNo) throws Exception {
        if (!telNo.matches("^([0-9\\-]{5,22})?$")) {
            throw new AppException("联系电话不合法");
        }
    }

    protected final void checkHomeTelNo(String homeTelNo) throws Exception {
        if (!homeTelNo.matches("^([0-9\\-]{5,22})?$")) {
            throw new AppException("住址电话不合法");
        }
    }

    protected final void checkOfficeTelNo(String officeTelNo) throws Exception {
        if (!officeTelNo.matches("^([0-9\\-]{5,22})?$")) {
            throw new AppException("办公电话不合法");
        }
    }

    protected final void checkMobileTelNo(String mobileTelNo) throws Exception {
        if (!mobileTelNo.matches("^([0-9\\-]{5,22})?$")) {
            throw new AppException("移动电话不合法");
        }
    }

    protected final void checkFaxNo(String faxNo) throws Exception {
        if (!faxNo.matches("^([0-9\\-]{5,22})?$")) {
            throw new AppException("传真号码不合法");
        }
    }

    protected final void checkEmail(String email) throws Exception {
        if (!email.matches("^.{10,40}$")) {
            throw new AppException("电子邮箱不合法");
        }
    }

    protected final void checkSex(String sex) throws Exception {
        if (!sex.matches("^[01]$")) {
            throw new AppException("性别不合法");
        }
    }

    protected final void checkBirthday(String birthday) throws Exception {
        if (!birthday.matches("^[0-9]{8}$")) {
            throw new AppException("生日不合法");
        }
    }

    protected final void checkIncome(String income) throws Exception {
        if (!income.matches("^([0-9]{1,8})?$")) {
            throw new AppException("年收入不合法");
        }
    }

    protected final void checkEducation(String education) throws Exception {
        if (!education.matches("^([0-9]{1,2})?$")) {
            throw new AppException("教育程度不合法");
        }
    }

    protected final void checkVocation(String vocation) throws Exception {
        if (!vocation.matches("^([0-9]{1,2})?$")) {
            throw new AppException("职业代码不合法");
        }
    }

    protected final void checkRiskTolerance(String riskTolerance) throws Exception {
        if (!riskTolerance.matches("^[0-9]{1}$")) {
            throw new AppException("风险承受能力不合法");
        }
    }

    protected final void checkTradingMethod(String tradingMethod) throws Exception {
        if (!tradingMethod.matches("^[01]{8}$")) {
            throw new AppException("交易方式不合法");
        }
    }

    protected final void checkTradePassword(String tradePassword) throws Exception {
        if (!tradePassword.matches("^.{4,64}$")) {
            throw new AppException("交易密码不合法");
        }
    }

    protected final void checkDeliverWay(String deliverWay) throws Exception {
        if (!deliverWay.matches("^[01]{8}$")) {
            throw new AppException("寄送选择不合法");
        }
    }

    protected final void checkDeliverType(String deliverType) throws Exception {
        if (!deliverType.matches("^[0-9]$")) {
            throw new AppException("寄送方式不合法");
        }
    }

    protected final void checkSHSecAccountID(String shSecAccountID) throws Exception {
        if (!shSecAccountID.matches("^.*$")) {
            throw new AppException("上交所证券帐号不合法");
        }
    }

    protected final void checkSZSecAccountID(String szSecAccountID) throws Exception {
        if (!szSecAccountID.matches("^.*$")) {
            throw new AppException("深交所证券帐号不合法");
        }
    }

    protected final void checkFreezingDeadline(String freezingDeadline) throws Exception {
        if (!freezingDeadline.matches("^[0-9]{8}$")) {
            throw new AppException("冻结截至日期不合法");
        }
    }

    protected final void checkFrozenCause(String frozenCause) throws Exception {
        if (!frozenCause.matches("^[0-9]$")) {
            throw new AppException("冻结原因不合法");
        }
    }

    protected final void checkBankCode(String bankCode) throws Exception {
        if (!bankCode.matches("^([0-9]{2,8})?$")) {
            throw new AppException("银行编号不合法");
        }
    }

    protected final void checkBankName(String bankName) throws Exception {
        if (!bankName.matches("^.{10,100}$")) {
            throw new AppException("银行全称不合法");
        }
    }

    protected final void checkBankAddress(String bankAddress) throws Exception {
        if (!bankAddress.matches("^.{0,60}$")) {
            throw new AppException("银行地址不合法");
        }
    }

    protected final void checkBankAcctName(String bankAcctName) throws Exception {
        if (!bankAcctName.matches("^.{2,60}$")) {
            throw new AppException("银行户名不合法");
        }
    }

    protected final void checkBankAcctNo(String bankAcctNo) throws Exception {
        if (!bankAcctNo.matches("^[0-9]{10,30}$")) {
            throw new AppException("银行卡号不合法");
        }
    }

    protected final void checkBankAcctVerified(String bankAcctVerified) throws Exception {
        if (!bankAcctVerified.matches("^[01]$")) {
            throw new AppException("银行账户是否通过验证不合法");
        }
    }

    protected final void checkOriginOrderSerialNo(String originOrderSerialNo) throws Exception {
        if (!originOrderSerialNo.matches("^[0-9]{8,24}$")) {
            throw new AppException("原委托流水不合法");
        }
    }

    protected final String SQL_WRITE_ORDER_ACCT = "" +
        "insert into OrderAcct" +
        "(" +
        "    orderSerialNo," +              //委托流水
        "    serviceCode," +                //功能码
        "    businessCode," +               //业务码
        "    acceptMethod," +               //受理方式
        "    regionCode," +                 //地区编号
        "    branchCode," +                 //网点编号
        "    netCode," +                    //销售网点编号
        "    opCode," +                     //柜员编号
        "    custAccountID," +              //客户帐号
        "    transAccountID," +             //交易帐号
        "    taAccountID," +                //基金帐号
        "    taCode," +                     //TA代码
        "    custType," +                   //客户类型
        "    custName," +                   //客户名称
        "    custNameAbbr," +               //客户简称
        "    nationality," +                //投资者国籍
        "    certType," +                   //证件类型
        "    certNo," +                     //证件号码
        "    certValidFrom," +              //证件有效期起始日期
        "    certValidTo," +                //证件有效期截至日期
        "    shSecAccountID," +             //上交所证券帐号
        "    szSecAccountID," +             //深交所证券帐号
        "    address," +                    //通讯地址
        "    postCode," +                   //邮政编码
        "    telNo," +                      //电话号码
        "    homeTelNo," +                  //住址电话
        "    officeTelNo," +                //办公电话
        "    mobileTelNo," +                //手机号码
        "    faxNo," +                      //传真号码
        "    email," +                      //E-MAIL地址
        "    birthday," +                   //出生日期
        "    sex," +                        //性别
        "    education," +                  //教育程度
        "    vocation," +                   //职业代码
        "    industry," +                   //行业代码
        "    marriage," +                   //婚姻状况
        "    income," +                     //年收入
        "    instType," +                   //机构类型
        "    instNature," +                 //机构性质
        "    instRegAddress," +             //机构注册地
        "    instRegCapital," +             //机构注册资本
        "    instEmployees," +              //机构员工数量
        "    instReprName," +               //法人姓名
        "    instReprCertType," +           //法人证件类型
        "    instReprCertNo," +             //法人证件号码
        "    instReprCertValidFrom," +      //法人证件有效期起始日期
        "    instReprCertValidTo," +        //法人证件有效期截至日期
        "    instTransName," +              //经办人姓名
        "    instTransCertType," +          //经办人证件类型
        "    instTransCertNo," +            //经办人证件号码
        "    instTransCertValidFrom," +     //经办人证件有效期起始日期
        "    instTransCertValidTo," +       //经办人证件有效期截至日期
        "    instTransTelNo," +             //经办人联系电话
        "    instTransMobileTelNo," +       //经办人移动电话
        "    broker," +                     //经纪人
        "    bankCode," +                   //银行代码
        "    bankAddress," +                //银行地址
        "    bankName," +                   //银行全称
        "    bankAcctName," +               //银行帐号户名
        "    bankAcctNo," +                 //银行帐号卡号
        "    bankAcctExpired," +            //银行账号有效期
        "    bankAcctVerified," +           //银行帐号验证
        "    deliverType," +                //对帐单寄送选择
        "    deliverWay," +                 //对账单寄送方式
        "    tradingMethod," +              //交易方式
        "    riskTolerance," +              //风险承受能力
        "    freezingDeadline," +           //冻结截至日期
        "    frozenCause," +                //冻结原因
        "    originOrderSerialNo," +        //原委托流水
        "    originAppSerialNo," +          //原申请流水
        "    inAdvanceFlag," +              //委托预约标志
        "    inAdvanceDate," +              //委托预约日期
        "    grantNeeded," +                //是否需要授权
        "    grantStatus," +                //授权标志(0-未授权 1-授权通过 2-授权不通过)
        "    grantOpCode," +                //授权操作员
        "    grantDate," +                  //授权日期
        "    grantTime," +                  //授权时间
        "    orderStatus," +                //委托状态
        "    orderDate," +                  //委托日期
        "    orderTime," +                  //委托时间
        "    summary" +                     //备注
        ")" +
        "values" +
        "(" +
        "    ?, " +                         //委托流水
        "    ?, " +                         //功能码
        "    ?, " +                         //业务码
        "    ?, " +                         //受理方式
        "    ?, " +                         //地区编号
        "    ?, " +                         //网点编号
        "    ?, " +                         //销售网点编号
        "    ?, " +                         //柜员编号
        "    ?, " +                         //客户帐号
        "    ?, " +                         //交易帐号
        "    ?, " +                         //基金帐号
        "    ?, " +                         //TA代码
        "    ?," +                          //客户类型
        "    ?," +                          //客户名称
        "    ?," +                          //客户简称
        "    ?," +                          //投资者国籍
        "    ?," +                          //证件类型
        "    ?," +                          //证件号码
        "    ?," +                          //证件有效期起始日期
        "    ?," +                          //证件有效期截至日期
        "    ?," +                          //上交所证券帐号
        "    ?," +                          //深交所证券帐号
        "    ?," +                          //通讯地址
        "    ?," +                          //邮政编码
        "    ?," +                          //电话号码
        "    ?," +                          //住址电话
        "    ?," +                          //办公电话
        "    ?," +                          //手机号码
        "    ?," +                          //传真号码
        "    ?," +                          //E-MAIL地址
        "    ?," +                          //出生日期
        "    ?," +                          //性别
        "    ?," +                          //教育程度
        "    ?," +                          //职业代码
        "    ?," +                          //行业代码
        "    ?," +                          //婚姻状况
        "    ?," +                          //年收入
        "    ?," +                          //机构类型
        "    ?," +                          //机构性质
        "    ?," +                          //机构注册地
        "    ?," +                          //机构注册资本
        "    ?," +                          //机构员工数量
        "    ?," +                          //法人姓名
        "    ?," +                          //法人证件类型
        "    ?," +                          //法人证件号码
        "    ?," +                          //法人证件有效期起始日期
        "    ?," +                          //法人证件有效期截至日期
        "    ?," +                          //经办人姓名
        "    ?," +                          //经办人证件类型
        "    ?," +                          //经办人证件号码
        "    ?," +                          //经办人证件有效期起始日期
        "    ?," +                          //经办人证件有效期截至日期
        "    ?," +                          //经办人联系电话
        "    ?," +                          //经办人移动电话
        "    ?," +                          //经纪人
        "    ?," +                          //银行代码
        "    ?," +                          //银行地址
        "    ?," +                          //银行全称
        "    ?," +                          //银行帐号户名
        "    ?," +                          //银行帐号卡号
        "    ?," +                          //银行账号有效期
        "    ?," +                          //银行帐号验证
        "    ?," +                          //对帐单寄送选择
        "    ?," +                          //对账单寄送方式
        "    ?," +                          //交易方式
        "    ?," +                          //风险承受能力
        "    ?," +                          //冻结截至日期
        "    ?," +                          //冻结原因
        "    ?," +                          //原委托流水
        "    ?," +                          //原申请流水
        "    ?," +                          //委托预约标志
        "    ?," +                          //委托预约日期
        "    ?," +                          //是否需要授权
        "    ?," +                          //授权标志(0-未授权 1-授权通过 2-授权不通过)
        "    ?," +                          //授权操作员
        "    ?," +                          //授权日期
        "    ?," +                          //授权时间
        "    ?," +                          //委托状态
        "    ?," +                          //委托日期
        "    ?," +                          //委托时间
        "    ?" +                           //备注
        ")";
}
